package books4africa

import static org.junit.Assert.*
import org.junit.*

class UserIntegrationTests {
	
	private User newUser(){
		return new User(
			username:'jjohns',
			password:'testOne',
			userType:'Admin',
			email:'jjohns@maine.edu',
			enabled:true
		)
	}
	
	void testNewUser(){
		def newUser = newUser().save(failOnEroor:true)
		
		def foundUser = User.get(newUser.id)
		
		assertEquals 'jjohns', foundUser.username
	}
	
	void testUserUpdate(){
		def newUser = newUser().save(failOnError:true)
		
		newUser.password = "adminPass"
		newUser.save()
		
		def foundUser = User.get(newUser.id)
		assertEquals 'adminPass', foundUser.password
	}
	
	void testUserDelete(){
		def newUser = newUser().save(failOnError:true)
		newUser.delete()
		assertFalse newUser.exists(newUser.id) 
	}
}
